<?php

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\model\GoodsBasicInfo;
$goods_id = 0;


$goodsinfo = GoodsBasicInfo::get('*', [
	'goods_id[>]' => $goods_id,
	'status' => [
		GoodsBasicInfo::STATUS_ONLINE,
		GoodsBasicInfo::STATUS_PASSED,
		GoodsBasicInfo::STATUS_OFFLINE,
		GoodsBasicInfo::STATUS_ADM_OFFLINE,
		GoodsBasicInfo::STATUS_WAIT_AUDIT,
	]
]);

$path = "/home/adm_rsync_dir/";

$setting = [
	[
		'price_range' => [0 ,99],
		'goods_nums' => 0,
		'file_name' => $path . "goods_price_range_0_99.text",
	],
	[
		'price_range' => [100 ,199],
		'goods_nums' => 0,
		'file_name' => $path . "goods_price_range_100_199.text",
	],
	[
		'price_range' => [200 ,299],
		'goods_nums' => 0,
		'file_name' => $path . "goods_price_range_200_299.text",
	],
	[
		'price_range' => [300 ,399],
		'goods_nums' => 0,
		'file_name' => $path . "goods_price_range_300_399.text",
	],
	[
		'price_range' => [400 ,499],
		'goods_nums' => 0,
		'file_name' => $path . "goods_price_range_400_499.text",
	],
	[
		'price_range' => [500 ,999],
		'goods_nums' => 0,
		'file_name' => $path . "goods_price_range_500_999.text",
	],
	[
		'price_range' => [1000 ,PHP_INT_MAX],
		'goods_nums' => 0,
		'file_name' => $path . "goods_price_range_1000_" . PHP_INT_MAX . ".text",
	],
];


foreach ($setting as $item) {
	file_put_contents($item['file_name'], "goods_id, goods_name, category_name\r\n", FILE_APPEND);
}



while ($goodsinfo) {

	$goods_id = $goodsinfo['goods_id'];
	$goodsDetail = \Biz\service\GoodsDetail::formatBasicInfos([$goods_id])[$goods_id];
	foreach ($setting as $item) {
		if ($item['price_range'][0] <= $goodsDetail['min_price'] && $item['price_range'][1] >= $goodsDetail['min_price']) {
			 $categoryname = implode("/",  array_column($goodsDetail['category'], 'cate_name'));
			file_put_contents($item['file_name'],$goodsDetail['goods_id'] . ", " . $goodsDetail['title'] . ", " . $categoryname . "\r\n", FILE_APPEND);
			echo $goods_id . " " . $categoryname . "\r\n";
			break;
		}
	}





	$goodsinfo = GoodsBasicInfo::get('*', [
		'goods_id[>]' => $goods_id,
		'status' => [
			GoodsBasicInfo::STATUS_ONLINE,
			GoodsBasicInfo::STATUS_PASSED,
			GoodsBasicInfo::STATUS_OFFLINE,
			GoodsBasicInfo::STATUS_ADM_OFFLINE,
			GoodsBasicInfo::STATUS_WAIT_AUDIT,
		]
	]);
}
